{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "e5eb65df",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_values(['88150.77678', '0', '0.8280059462620806', '0.5314327126985153', '0.39750946211500204', '88150.77678-0', '28.369752901573236', '52.033134560158175', '705.1211159195539', '20.0', '15.0', '-20.0', '0.01152676874215287', '0.051001789765111646', '0.9986320398640939'])\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "import datetime\n",
    "import time\n",
    "\n",
    "gz = open('gaze.csv')\n",
    "gz_lines = gz.readline().rstrip().split(',')\n",
    "#print(gz_lines)\n",
    "#cnt = 0\n",
    "row_lists = []\n",
    "for row in gz.readlines():\n",
    "    row = row.rstrip().split(',')\n",
    "    row_list = [data for data in row if data != '']\n",
    "    row_dict = dict(zip(gz_lines,row_list))\n",
    "    row_lists.append(row_dict)\n",
    "print(row_lists[0].values())\n",
    "#print(row_lists)\n",
    "#cnt += 1\n",
    "#if(cnt >= 3):\n",
    "#break;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "a8bcfab8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "87442\n"
     ]
    }
   ],
   "source": [
    "#exercise 1\n",
    "\n",
    "#print(len(row_lists))\n",
    "#for i in range(len(row_lists)):\n",
    "row_lists = [row for row in row_lists if float(row['confidence']) >= 0.9]\n",
    "print(len(row_lists))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "b2a91d57",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "120036\n"
     ]
    }
   ],
   "source": [
    "#exercise 2\n",
    "\n",
    "def get_mean(rows,x):\n",
    "    cal_sum = 0.0\n",
    "    for row in rows:\n",
    "        cal_sum += float(row[x])\n",
    "    cal_sum /= len(rows)\n",
    "    return cal_sum\n",
    "\n",
    "def get_sigma(rows,x,x_mean):\n",
    "    cal_sum = 0.0\n",
    "    for row in rows:\n",
    "        cal_sum += pow(float(row[x])-x_mean,2)\n",
    "    cal_sum /= len(rows)\n",
    "    cal_sum = math.sqrt(cal_sum)\n",
    "    return cal_sum\n",
    "    \n",
    "def three_sigma(rows):\n",
    "    new_row_list = []\n",
    "    meanx = get_mean(rows,'norm_pos_x')\n",
    "    meany = get_mean(rows,'norm_pos_y')\n",
    "    sigmax = get_sigma(rows,'norm_pos_x',meanx)\n",
    "    sigmay = get_sigma(rows,'norm_pos_y',meany)\n",
    "    for row in rows:\n",
    "        if(((float(row['norm_pos_x']) <= meanx+3*sigmax) and (float(row['norm_pos_x']) >= meanx-3*sigmax)) and ((float(row['norm_pos_y']) <= meany+3*sigmay) and (float(row['norm_pos_y']) >= meany-3*sigmay))):\n",
    "            new_row_list.append(row)\n",
    "    return new_row_list\n",
    "\n",
    "row_lists = three_sigma(row_lists)\n",
    "print(len(row_lists))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c6026381",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1970-01-02T00:29:10.776780+00:00\n"
     ]
    }
   ],
   "source": [
    "#exercise 3\n",
    "\n",
    "for row in row_lists:\n",
    "    utc_t = datetime.datetime.utcfromtimestamp(float(row['gaze_timestamp']))\n",
    "    #row['gaze_timestamp'] = datetime.datetime.utcnow().isoformat()\n",
    "    row['gaze_timestamp'] = utc_t.replace(tzinfo=datetime.timezone.utc).isoformat()\n",
    "row_example = row_lists[0]\n",
    "print(row_example['gaze_timestamp'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "331af00c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "427.62610766083765\n"
     ]
    }
   ],
   "source": [
    "#exercise 4\n",
    "\n",
    "start_line = row_lists[0]\n",
    "start_time = float(start_line['gaze_timestamp'])\n",
    "#start_time = datetime.datetime.fromtimestamp(float(start_line['gaze_timestamp']))\n",
    "end_line = row_lists[-1]\n",
    "end_time = float(end_line['gaze_timestamp'])\n",
    "#end_time = datetime.datetime.fromtimestamp(float(end_line['gaze_timestamp']))\n",
    "sample_rate = len(row_lists) / (end_time-start_time)\n",
    "print(sample_rate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "d7fcfd59",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_values(['88150.77678', '0', '0.8280059462620806', '0.5314327126985153', '0.39750946211500204', '88150.77678-0', '28.369752901573236', '52.033134560158175', '705.1211159195539', '20.0', '15.0', '-20.0', '0.01152676874215287', '0.051001789765111646', '0.9986320398640939'])\n",
      "{'gaze_timestamp': 88150.78678, 'world_index': '0', 'confidence': '0.5502584923810523', 'norm_pos_x': '0.33792335450596644', 'norm_pos_y': '0.17330059543683884', 'base_data': '88150.779759-1', 'gaze_point_3d_x': '-141.8791689729382', 'gaze_point_3d_y': '160.8677791527232', 'gaze_point_3d_z': '683.8931076235057', 'eye_center0_3d_x': '-39.93492801030824', 'eye_center0_3d_y': '14.997919452545707', 'eye_center0_3d_z': '-20.075282531198983', 'gaze_normal0_x': '-0.14039693931103547', 'gaze_normal0_y': '0.2008910130307643', 'gaze_normal0_z': '0.9695006448247298'}\n",
      "{'gaze_timestamp': 88150.79677999999, 'world_index': '1', 'confidence': '0.7063552247599557', 'norm_pos_x': '0.49397474725559637', 'norm_pos_y': '0.4084287570104117', 'base_data': '88150.79569-0 88150.795675-1', 'gaze_point_3d_x': '2.226757768794034', 'gaze_point_3d_y': '-19.036159854780287', 'gaze_point_3d_z': '-288.72722534107356', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.06514516047431963', 'gaze_normal0_y': '0.027374145920454677', 'gaze_normal0_z': '0.9975002577452808', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.1530847520875171', 'gaze_normal1_y': '0.2209875356663993', 'gaze_normal1_z': '0.9631871924804625'}\n",
      "{'gaze_timestamp': 88150.80677999998, 'world_index': '1', 'confidence': '0.7910322078633543', 'norm_pos_x': '0.49472831656855015', 'norm_pos_y': '0.40514624513285424', 'base_data': '88150.804471-0 88150.80479-1', 'gaze_point_3d_x': '1.9446636659802365', 'gaze_point_3d_y': '-19.682136143449362', 'gaze_point_3d_z': '-288.19418100551803', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.06623886767176704', 'gaze_normal0_y': '0.023517941823706083', 'gaze_normal0_z': '0.9975266005585715', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.15222844217062562', 'gaze_normal1_y': '0.22981420200416583', 'gaze_normal1_z': '0.9612553947580701'}\n",
      "{'gaze_timestamp': 88150.81677999998, 'world_index': '2', 'confidence': '0.8361660611207393', 'norm_pos_x': '0.49362903233597083', 'norm_pos_y': '0.40058294061730537', 'base_data': '88150.81599799999-0 88150.815997-1', 'gaze_point_3d_x': '2.3733773877048456', 'gaze_point_3d_y': '-20.832665442340023', 'gaze_point_3d_z': '-291.0391610701988', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.06396210553253093', 'gaze_normal0_y': '0.024893336791321347', 'gaze_normal0_z': '0.9976418048775022', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.15209387168484892', 'gaze_normal1_y': '0.23398036211890086', 'gaze_normal1_z': '0.960271130638957'}\n",
      "{'gaze_timestamp': 88150.82677999997, 'world_index': '2', 'confidence': '0.9151973420751922', 'norm_pos_x': '0.4936116815701956', 'norm_pos_y': '0.39895021008258913', 'base_data': '88150.827729-0 88150.823548-1', 'gaze_point_3d_x': '2.4128100758327182', 'gaze_point_3d_y': '-21.468145193186366', 'gaze_point_3d_z': '-295.0710570327717', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.06288346587545898', 'gaze_normal0_y': '0.02509974236087054', 'gaze_normal0_z': '0.9977052032804625', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.15004148584820762', 'gaze_normal1_y': '0.23453606423953438', 'gaze_normal1_z': '0.9604584254903964'}\n",
      "{'gaze_timestamp': 88150.83677999997, 'world_index': '2', 'confidence': '0.8981226615721961', 'norm_pos_x': '0.49311319524399827', 'norm_pos_y': '0.3989479733166602', 'base_data': '88150.83570099999-0 88150.83570099999-1', 'gaze_point_3d_x': '2.580643834051319', 'gaze_point_3d_y': '-21.2999141960879', 'gaze_point_3d_z': '-292.7523092034187', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.06281947395024938', 'gaze_normal0_y': '0.027157390027912388', 'gaze_normal0_z': '0.9976553462290907', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.15188909468215658', 'gaze_normal1_y': '0.23346737957802458', 'gaze_normal1_z': '0.9604283864971951'}\n",
      "{'gaze_timestamp': 88150.84677999996, 'world_index': '2', 'confidence': '0.8762689020545384', 'norm_pos_x': '0.49287244828606297', 'norm_pos_y': '0.39792630733730605', 'base_data': '88150.843448-0 88150.84344899999-1', 'gaze_point_3d_x': '2.70037871965768', 'gaze_point_3d_y': '-21.753074785467472', 'gaze_point_3d_z': '-295.9881540539876', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.0616606383371786', 'gaze_normal0_y': '0.027373421145385487', 'gaze_normal0_z': '0.9977217355027653', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.1505621238051983', 'gaze_normal1_y': '0.23344803725625876', 'gaze_normal1_z': '0.960642004482663'}\n",
      "{'gaze_timestamp': 88150.85677999996, 'world_index': '3', 'confidence': '0.8028764861728308', 'norm_pos_x': '0.4927015882674469', 'norm_pos_y': '0.39856962598805834', 'base_data': '88150.85654-0 88150.85654-1', 'gaze_point_3d_x': '2.766044192974574', 'gaze_point_3d_y': '-21.623266864181776', 'gaze_point_3d_z': '-296.08798529724027', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.06140321642039546', 'gaze_normal0_y': '0.025916912799037132', 'gaze_normal0_z': '0.9977765073623442', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.15073019651578715', 'gaze_normal1_y': '0.2338791905465301', 'gaze_normal1_z': '0.960510766252837'}\n",
      "{'gaze_timestamp': 88150.86677999995, 'world_index': '3', 'confidence': '0.922197307158175', 'norm_pos_x': '0.4925920221557682', 'norm_pos_y': '0.39870466654079517', 'base_data': '88150.867514-0 88150.86451599999-1', 'gaze_point_3d_x': '2.8279107518092026', 'gaze_point_3d_y': '-21.750937954882396', 'gaze_point_3d_z': '-298.2332454694398', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.06071702183202721', 'gaze_normal0_y': '0.025219893820897885', 'gaze_normal0_z': '0.9978363594375146', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.14981428045739542', 'gaze_normal1_y': '0.2335102349998405', 'gaze_normal1_z': '0.9607438011880963'}\n",
      "{'gaze_timestamp': 88150.87677999995, 'world_index': '3', 'confidence': '0.7797779563318543', 'norm_pos_x': '0.4920490799623768', 'norm_pos_y': '0.3986402655486505', 'base_data': '88150.87172699999-0 88150.87545699999-1', 'gaze_point_3d_x': '3.0366961074587433', 'gaze_point_3d_y': '-21.77569063112226', 'gaze_point_3d_z': '-298.38293212936594', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.05994958006002151', 'gaze_normal0_y': '0.025324603360997427', 'gaze_normal0_z': '0.997880109189093', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.1504509230615827', 'gaze_normal1_y': '0.2334355900843485', 'gaze_normal1_z': '0.9606624511408207'}\n",
      "{'gaze_timestamp': 88150.88677999994, 'world_index': '4', 'confidence': '0.9336578810932825', 'norm_pos_x': '0.49216591828673045', 'norm_pos_y': '0.3991673717146227', 'base_data': '88150.88389-0 88150.88827099999-1', 'gaze_point_3d_x': '2.993379604392894', 'gaze_point_3d_y': '-21.671916187220244', 'gaze_point_3d_z': '-298.5133295164393', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.06007445660943474', 'gaze_normal0_y': '0.024427210448378187', 'gaze_normal0_z': '0.997894969950642', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.1502346770715741', 'gaze_normal1_y': '0.23348674078640194', 'gaze_normal1_z': '0.9606838625074033'}\n",
      "{'gaze_timestamp': 88150.89677999994, 'world_index': '4', 'confidence': '0.8550647363113325', 'norm_pos_x': '0.49196301857445757', 'norm_pos_y': '0.3980274149338666', 'base_data': '88150.89551599999-0 88150.891702-1', 'gaze_point_3d_x': '3.1042410838204244', 'gaze_point_3d_y': '-22.154830596727386', 'gaze_point_3d_z': '-301.7536334011173', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.05899829367017455', 'gaze_normal0_y': '0.024598649249555092', 'gaze_normal0_z': '0.9979549628110009', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.14891582435890977', 'gaze_normal1_y': '0.23373323204977325', 'gaze_normal1_z': '0.9608292530367055'}\n",
      "{'gaze_timestamp': 88150.90677999993, 'world_index': '4', 'confidence': '0.860093311910097', 'norm_pos_x': '0.49155932443364775', 'norm_pos_y': '0.3981537095713097', 'base_data': '88150.90741599999-0 88150.90357499999-1', 'gaze_point_3d_x': '3.2627763654987465', 'gaze_point_3d_y': '-22.145110012300265', 'gaze_point_3d_z': '-301.9952627615938', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.05839478901870607', 'gaze_normal0_y': '0.02400047627187978', 'gaze_normal0_z': '0.998005022910298', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.14932225425095516', 'gaze_normal1_y': '0.23403121968543314', 'gaze_normal1_z': '0.9606936309760579'}\n",
      "{'gaze_timestamp': 88150.91677999993, 'world_index': '5', 'confidence': '0.9291327620219251', 'norm_pos_x': '0.4914388450903873', 'norm_pos_y': '0.39748146803382634', 'base_data': '88150.91139099999-0 88150.91700799999-1', 'gaze_point_3d_x': '3.3142014956882235', 'gaze_point_3d_y': '-22.32397147411286', 'gaze_point_3d_z': '-302.4381576835125', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.05812076850806207', 'gaze_normal0_y': '0.02427722241941762', 'gaze_normal0_z': '0.9980143249170481', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.14925633872709826', 'gaze_normal1_y': '0.2345754008162153', 'gaze_normal1_z': '0.9605711460801297'}\n",
      "{'gaze_timestamp': 88150.92677999992, 'world_index': '5', 'confidence': '0.8833800162178242', 'norm_pos_x': '0.49148149130484464', 'norm_pos_y': '0.3959650494113467', 'base_data': '88150.923423-0 88150.92752699999-1', 'gaze_point_3d_x': '3.311363663876099', 'gaze_point_3d_y': '-22.74809848858154', 'gaze_point_3d_z': '-303.6919905798173', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.05787439261660966', 'gaze_normal0_y': '0.026257329940315228', 'gaze_normal0_z': '0.9979785104418155', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.14860165931375657', 'gaze_normal1_y': '0.2343942415664973', 'gaze_normal1_z': '0.9607168606669007'}\n",
      "{'gaze_timestamp': 88150.93677999992, 'world_index': '5', 'confidence': '0.9976716979910984', 'norm_pos_x': '0.49109736711588986', 'norm_pos_y': '0.3962520166514687', 'base_data': '88150.93622799999-0 88150.936133-1', 'gaze_point_3d_x': '3.4655296294769027', 'gaze_point_3d_y': '-22.717123650092198', 'gaze_point_3d_z': '-304.1173390246404', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.05725573600184664', 'gaze_normal0_y': '0.02556757341574248', 'gaze_normal0_z': '0.9980321036342059', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.14890087750610775', 'gaze_normal1_y': '0.23447839734970133', 'gaze_normal1_z': '0.9606499934181163'}\n",
      "{'gaze_timestamp': 88150.94677999991, 'world_index': '6', 'confidence': '0.9147837667828747', 'norm_pos_x': '0.4913582478042822', 'norm_pos_y': '0.3960199736965523', 'base_data': '88150.94368499999-0 88150.947523-1', 'gaze_point_3d_x': '3.374399071467657', 'gaze_point_3d_y': '-22.838474090435426', 'gaze_point_3d_z': '-305.05957760399974', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.05738168673496691', 'gaze_normal0_y': '0.025708572282394638', 'gaze_normal0_z': '0.9980212479394674', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.14811747558506844', 'gaze_normal1_y': '0.23433106058094225', 'gaze_normal1_z': '0.9608070396668197'}\n",
      "{'gaze_timestamp': 88150.9567799999, 'world_index': '6', 'confidence': '0.8788892496462954', 'norm_pos_x': '0.49133863500720726', 'norm_pos_y': '0.39775552495347044', 'base_data': '88150.955483-0 88150.95548399999-1', 'gaze_point_3d_x': '3.3662896201724912', 'gaze_point_3d_y': '-22.352572589595262', 'gaze_point_3d_z': '-303.6373329086299', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.057698371646870764', 'gaze_normal0_y': '0.023702105049595353', 'gaze_normal0_z': '0.9980526579923118', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.1488208667257802', 'gaze_normal1_y': '0.23427704473976166', 'gaze_normal1_z': '0.9607115154587205'}\n",
      "{'gaze_timestamp': 88150.9667799999, 'world_index': '6', 'confidence': '0.8391189191753998', 'norm_pos_x': '0.49111486313443464', 'norm_pos_y': '0.3973271674120443', 'base_data': '88150.963521-0 88150.967437-1', 'gaze_point_3d_x': '3.4685423579279355', 'gaze_point_3d_y': '-22.545556050882794', 'gaze_point_3d_z': '-304.9810889951628', 'eye_center0_3d_x': '20.0', 'eye_center0_3d_y': '15.0', 'eye_center0_3d_z': '-20.0', 'gaze_normal0_x': '0.057074997183387884', 'gaze_normal0_y': '0.023794625042328963', 'gaze_normal0_z': '0.9980862991323006', 'eye_center1_3d_x': '-39.93492801030824', 'eye_center1_3d_y': '14.997919452545707', 'eye_center1_3d_z': '-20.075282531198983', 'gaze_normal1_x': '-0.1484760207186315', 'gaze_normal1_y': '0.23430510114919034', 'gaze_normal1_z': '0.9607580292909492'}\n"
     ]
    }
   ],
   "source": [
    "#exercise 5\n",
    "\n",
    "time_limit = 0.01\n",
    "new_data = []\n",
    "cnt = 0\n",
    "lst_time = 0.0\n",
    "for i in range(len(row_lists)):\n",
    "    temp = row_lists[i]\n",
    "    if(cnt == 0):\n",
    "        new = temp\n",
    "        new_data.append(new)\n",
    "        cnt += 1\n",
    "        lst_time = float(new['gaze_timestamp'])\n",
    "        print(new.values())\n",
    "        lst_time += 0.01\n",
    "    elif (float(temp['gaze_timestamp']) >= lst_time):\n",
    "        if((float(temp['gaze_timestamp'])-lst_time) > (lst_time-float(temp['gaze_timestamp']))):\n",
    "            new = row_lists[i]\n",
    "        else:\n",
    "            new = row_lists[i-1]\n",
    "        new['gaze_timestamp'] = lst_time\n",
    "        new_data.append(new.values())\n",
    "        lst_time += 0.01\n",
    "        cnt += 1\n",
    "        if(cnt <= 20):\n",
    "            print(new)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
